package com.itboye.sunsun.mycollect.fragments;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.itboye.sunsun.R;
import com.itboye.sunsun.Application.App;
import com.itboye.sunsun.adapter.CollectWordsAdapter;
import com.itboye.sunsun.adapter.MyCollectAdapter;
import com.itboye.sunsun.beans.MyCollectBean;
import com.itboye.sunsun.custome.XListView;
import com.itboye.sunsun.support.BaseFragment;

@SuppressLint("ValidFragment")
public class CollectWordsFragment extends BaseFragment implements
		OnItemClickListener {

	private Context context;
	private XListView xlistview;
	private CollectWordsAdapter mAdapter;
	private List<MyCollectBean> list;
	private View v;

	public CollectWordsFragment(Context context) {
		this.context = context;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		v = inflater.inflate(R.layout.fragment_mycollectwords, null);

		initData();
		return v;
	}

	public void initData() {

		xlistview = (XListView) v.findViewById(R.id.xlistview);
		list = new ArrayList<MyCollectBean>();
		MyCollectBean bean = new MyCollectBean();
		bean.setType("hah");
		MyCollectBean bean1 = new MyCollectBean();
		bean1.setType("a");
		MyCollectBean bean2 = new MyCollectBean();
		bean2.setType("1");
		list.add(bean);
		list.add(bean1);
		list.add(bean2);
		mAdapter = new CollectWordsAdapter(App.ctx, list);
		xlistview.setAdapter(mAdapter);
		xlistview.setOnItemClickListener(this);

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View view, int position,
			long arg3) {
		
		
		//Toast.makeText(App.ctx, ""+position, 0).show();
		MyCollectBean myCollectBean = list.get(position - 1);
		myCollectBean.setSelected(!myCollectBean.isSelected());
		mAdapter.notifyDataSetChanged();

	}

}
